package com.dog.basics.mqtt.receive;


import cn.hutool.core.util.StrUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
/**
 * @description: 接收消息业务 [需要放到API层 - 放到这里就是实例]
 * @author: He
 * @date: Created in 2020/10/15 14:42
 * @version: 1.0
 * @modified By:
 */
//@Component
@Log4j2
public class MqttMessageReceiver implements MessageHandler {

    /**
     * 业务 - 执行
     *
     * @param message
     * @throws MessagingException
     */
    @Override
    public void handleMessage(Message<?> message) throws MessagingException {
        log.info("--------------------接收到订阅消息-------------------- ");
        String topic = StrUtil.toString(message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC));
        String[] split = topic.split("/");
        log.info("{}  :  {} ：{}", topic, split[3], message.getPayload());
        String payloadData= StrUtil.toString(message.getPayload());
    }
}
